package com.bawei.week3.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import com.bawei.week3.Main2Activity;
import com.bawei.week3.R;
import com.bawei.week3.adapter.ContactADapter;
import com.bawei.week3.entity.ContactsEntity;
import com.bawei.week3.service.NumService;
import com.bawei.week3.utils.ContentUtils;

import java.util.List;

import androidx.fragment.app.Fragment;

/**
 * A simple {@link Fragment} subclass.
 */
public class ContactsFragment extends Fragment {
    private List<ContactsEntity> list;
    private ListView listView;
    private ContactADapter contactADapter;


    public ContactsFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_contacts, container, false);
        listView = view.findViewById(R.id.lv);
        list = ContentUtils.getContacts(getContext());
        contactADapter  = new ContactADapter(list,getContext());
        listView.setAdapter(contactADapter);
        //点击启动服务
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), NumService.class);
                getActivity().startService(intent);

                //跳转页面
                Intent intent1 = new Intent(getActivity(), Main2Activity.class);
                startActivity(intent1);
            }
        });


        return view;
    }

}
